package com.basic.business.common.utils;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

@Configuration
public class ExecutorConfig {

    @Bean("orderExecutor")
    public ExecutorService orderExecutor() {
        int corePoolSize = 10;
        return Executors.newFixedThreadPool(corePoolSize, new ThreadFactory() {
            private final ThreadFactory defaultFactory = Executors.defaultThreadFactory();

            @Override
            public Thread newThread(Runnable r) {
                Thread thread = defaultFactory.newThread(r);
                thread.setName("OrderProcessorThread-" + thread.getId());
                return thread;
            }
        });
    }
}

